import random
import time
import math

WIDTH = 800
HEIGHT = 800

BACK_COLOR = (0, 0, 0)

class MyRect:
    def __init__(self, x, y, w, h, clr):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.clr = clr

    def Draw(self):
        rc = Rect((self.x, self.y), (self.w, self.h))
        screen.draw.filled_rect(rc, self.clr)

def RandomColor():
    return (random.randint(50, 250), random.randint(50, 250), random.randint(50, 250))

w = 240
h = 400

x = 0
y = 0

FPS = ""
resultText = ""

rc = MyRect(x, y, w, h, (100, 100, 100))
rcLst = []
rcLst.append(rc)

lastUpdateTime = 0
lastTime = 0

def test(a, b):
    return a + b

print(test(b = 20, a = 30))

def on_key_down(key):
    global x, y, w, h
    global resultText
    if key == keys.SPACE:
        if w != h:
            if w > h:
                rc = MyRect(x, y, h, h, RandomColor())
                rcLst.append(rc)
                x += h
                w = w - h
            else:
                rc = MyRect(x, y, w, w, RandomColor())
                rcLst.append(rc)
                y += w
                h = h - w
        if w == h:
            resultText = "gcd is:" + str(w)

def update():
    global FPS
    global lastTime, lastUpdateTime
    
    accumTime = time.time() - lastUpdateTime
    t = time.time() - lastTime
    lastTime = time.time()
    if accumTime > 1:
        FPS = "FPS:" + str(math.floor(1 / t))
        lastUpdateTime = time.time()

def draw():
    screen.clear()
    screen.fill(BACK_COLOR)
    for rc in rcLst:
        rc.Draw()

    screen.draw.text(FPS, midtop = (700, 50))
    screen.draw.text(resultText, midtop = (700, 700))